import { Inject, Injectable, NestMiddleware } from '@nestjs/common';
import { NextFunction, Request, Response } from 'express';
import { UseAopService } from './use-aop.service';

// 中间件
@Injectable()
export class UseAopMiddleware implements NestMiddleware {
  @Inject(UseAopService)
  private useAopService: UseAopService;

  use(req: Request, res: Response, next: NextFunction) {
    console.log('befor 中间件', req.url);
    console.log('调用注入的服务', this.useAopService.findOne(1));
    next();
    console.log('after 中间件', res.statusCode);
  }
}
